<template>
    <div class="e-news-info clearfix" @mouseenter="hover = true" @mouseleave="hover = false">
        <div class="thumb" v-if="image" @click="$gotoUrl">
            <div class="img-box pb100">
                <div class="img" :style="{ 'background-image': 'url(' + $getImage(image) + ')' }"></div>
            </div>
        </div>
        <div class="news-content-text" :class="{ 'not-thumb': !image }">
            <h3 @click="$gotoUrl">{{ title }}</h3>
            <div class="description" v-html="$substr(description, len)"></div>
            <div class="other-content">
                <slot></slot>
            </div>
        </div>
    </div>
</template>

<style type="text/scss" lang="scss">
div.e-news-info {
    margin-bottom: 15px;
    background: #ffffff;
    position: relative;
    transition: border 0.3s, box-shadow 0.3s;
    border: 1px solid transparent;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);

    &:hover {
        border: 1px solid #1cbbb4;
        box-shadow: 0 4px 16px rgba(0, 123, 255, 0.2);
    }

    .thumb {
        float: left;
        width: 120px;
        margin-right: 15px;
        cursor: pointer;

        .img-box {
            position: relative;
            padding-bottom: 100%;
            overflow: hidden;
            width: 100%;
            height: 100%;
        }
    }

    .news-content-text {
        overflow: hidden;

        h3 {
            cursor: pointer;
            font-size: 18px;
            margin: 0;
            font-weight: 700;
            color: #333;
            transition: color 0.3s;

            &:hover {
                color: #1cbbb4;
            }
        }

        .description {
            color: #7b7b7b;
            line-height: 1.5;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }

        .other-content {
            margin-top: 10px;

            span {
                display: inline-block;
                margin-right: 8px;
                color: #555;
                font-size: 14px;
            }
        }
    }

    .news-content-text.not-thumb {
        margin-left: 0;
    }
}

@media screen and (max-width: 768px) {
    .e-news-info {
        .thumb {
            width: 100px;
            margin-right: 10px;
        }

        .news-content-text {
            margin-left: 110px;

            .other-content {
                left: 110px;
            }

            .description {
                word-break: break-all;
                display: -webkit-box;
                -webkit-box-orient: vertical;
                -webkit-line-clamp: 2;
                overflow: hidden;
            }
        }
    }
}
</style>

<script>
import gotoUrl from "../mixins/gotoUrl";

export default {
    name: "e-news-list",
    data() {
        return {
            hover: false
        }
    },
    mixins: [gotoUrl],
    props: {
        image: String,
        title: String,
        description: [String, Number],
        len: {
            type: Number,
            default: 30
        }
    },
    computed: {},
    methods: {},
    created() { },
    mounted() { },
    destroyed() { }
}
</script>
